<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'
// import {getFormatDateTime} from '@/utils'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        orderNo: {
          label: '订单编号',
          disabled: true
        },
        productId: {
          label: '产品',
          type: 'list',
          filterable: true,
          disabled: true,
          list: [],
          placeholder: '请选择产品',
        },
        unitPrice: {
          label: '光瓶单价',
          type: 'number',
          max: 1000,
          disabled: true,
          min: 0,
          default: 0
        },
        modelId: {
          label: '模具',
          type: 'list',
          filterable: true,
          clearable: true,
          placeholder: '请选择模具',
          list: []
        },
        bottleOutDiameter: {
          label: '瓶口外径'
        },
        bottleInDiameter: {
          label: '瓶口内径'
        },
        headNeckHeight: {
          label: '头经高度',
          type: 'number',
          max: 1000,
          default: 0
        },
        bottleLength: {
          label: '瓶长',
          type: 'number',
          max: 1000,
          default: 0
        },
        bottleWeight: {
          label: '瓶宽',
          type: 'number',
          max: 1000,
          default: 0
        },
        bottleHeight: {
          label: '瓶高',
          type: 'number',
          max: 1000,
          default: 0
        },
        clientProductNo: {
          label: '客户产品编码'
        },
        productWeight: {
          label: '标准克重',
          type: 'number',
          disabled: true,
          max: 1000
        },
        orderProductNumber: {
          label: '订单数量',
          type: 'number',
          disabled: true,
          max: 10000000
        },
        weightScope: {
          label: '克重误差范围(±)',
          default: '±'
        },
        productVolume: {
          label: '标准容量',
          type: 'number',
          disabled: true,
          max: 1000
        },
        volumeScope: {
          label: '容量范围(±)',
          default: '±'
        },

        customerProductStyle: {
          label: '客户样品',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 0
        },
        bottleCapSuit: {
          label: '瓶盖套装',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 0
        },
        specialMark: {
          label: '箱唛类型',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '普英唛', label: 0, tagType: 'success'},
            {text: '专用唛', label: 1},
            {text: '普英唛+H', label: 2,tagType: 'warning'}
          ],
          default: 0
        },
        boxPackImage: {
          label: '箱唛图片（侧）',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        },
        boxPackImageFront:{
          label: '箱唛图片（正）',
          type: 'uploadImage',
          imageType: 'uploadProductImage'
        },
        boxPackText: {
          label: '箱唛文字描述',
          inputType: 'textarea',
          placeholder: '请输入箱唛文字描述'
        },
        boxAudit: {
          label: '纸箱审核状态',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '未审核', label: 0},
            {text: '纸箱驳回', label: 2},
            {text: '已审核', label: 1}
          ],
          default: 0
        },
        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        }
      }
    }
  },
  methods: {
    /**
     * 初始化瓶配信息列表
     * @param attrName 瓶配信息属性名
     */
    // initBottleSuitList(attrName = 'bottleSuitList') {
    //   mRequest('systemApi/getSysDictLabelTreeList', {}, (res) => {
    //     this.dataFormConfig[attrName].list = this.R.pathOr([], ['data', 'list'], res)
    //   })
    // },
    /**
     * 成模数量变化时的回调
     */
    /**
     * 产品选择后的回调
     * @param value 选择的产品
     */
    productSelectCallback(value) {
      if (window.R.isNil(value)) {
        return
      }
      mRequest('productApi/productInfoInfo', {id: value}, (res) => {
        const productInfo = this.R.path(['data', 'productInfo'], res)

        this.dataForm['modelId'] = productInfo['modelId']
        this.dataForm['productWeight'] = productInfo['productWeight']
        // this.dataForm['deepStatus'] = this.R.gt(this.R.length(productInfo['deepCategoryList']), 0) ? 1 : 0
        // this.dataForm['deepCategoryList'] = productInfo['deepCategoryList']
        this.dataForm['bottleInDiameter'] = productInfo['bottleInDiameter']
        this.dataForm['bottleOutDiameter'] = productInfo['bottleOutDiameter']
        this.dataForm['bottleCapSuit'] = productInfo['productAssort']
        this.dataForm['weightScope'] = this.R.isNil(productInfo['weightScope']) ? '±' : productInfo['weightScope']
        this.dataForm['headNeckHeight'] = productInfo['headNeckHeight']
        this.dataForm['productVolume'] = productInfo['productVolume']
        this.dataForm['volumeScope'] = this.R.isNil(productInfo['volumeScope']) ? '±' : productInfo['volumeScope']
        this.dataForm['deviceId'] = productInfo['deviceId']
        this.dataForm['bottleLength'] = productInfo['bottleLength']
        this.dataForm['bottleWeight'] = productInfo['bottleWeight']
        this.dataForm['bottleHeight'] = productInfo['bottleHeight']
      })
    },
    modelIdSelectCallback() {
      if (window.R.isEmpty(this.dataForm.modelId)) {
        this.dataForm.leftSuccessMo = 0
        this.dataForm.leftPrimaryMo = 0
        this.dataForm.leftJiaZi = 0
        this.dataForm.leftKouZi = 0
        this.dataForm.leftLengQue = 0
        this.dataForm.leftLouDou = 0
        this.dataForm.leftMenTou = 0
        this.dataForm.leftQiTou = 0
        this.dataForm.leftXinZi=0
        return
      }
      mRequest('modelApi/modelInfoInfo', {id: this.dataForm.modelId}, (res) => {
        const {data} = res
        const {modelInfo} = data
        const {successMo, primaryMo, jiaZi, kouZi, lengQue, louDou, menTou, qiTou, xinZi} = modelInfo
        this.dataForm.leftSuccessMo = successMo
        this.dataForm.leftPrimaryMo = primaryMo
        this.dataForm.leftJiaZi = jiaZi
        this.dataForm.leftKouZi = kouZi
        this.dataForm.leftLengQue = lengQue
        this.dataForm.leftLouDou = louDou
        this.dataForm.leftMenTou = menTou
        this.dataForm.leftQiTou = qiTou
        this.dataForm.leftXinZi = xinZi
      })
    },
    init(id, property,cb) {
      this.dataForm.id = id || 0
   //   this.initBottleSuitList()
      this.initModelInfoList('modelId')
      this.initProductInfoList()
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        stepsConfig: this.stepsConfig,
        dataRule: this.getNeedDataRule('orderTime', 'clientId', 'deliveryTime', 'productId', 'deviceId', 'orderProductNumber',  'bottleLength', 'bottleWeight', 'bottleHeight'),
        initApi: 'orderApi/orderDetailInfo',
        saveApi: 'orderApi/saveOrderDetail',
        updateApi: 'orderApi/updateOrderDetail',
        objectName: 'orderDetail',
        submitCallback: cb
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    }
  }
}
</script>
